package com.genesis.yunnanji.view;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.AndroidCharacter;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.genesis.yunnanji.R;


/**
 * 
 * @author ywl
 * 
 */
public class TextInputDialog extends Dialog {

	private Context context;
	private Button cancel;
	private Button comfir;
	private EditText editText;
	private TextWatcher watcher;
	private TextView title;
	Callback dialogcallback;
	private View.OnClickListener onClickListener;

	public TextInputDialog(final Context context) {
		super(context, R.style.ShareDialog);
		this.context = context;
		setContentView(R.layout.view_textinputdialog);

		comfir = (Button) findViewById(R.id.textinputdialog_comfir);
		cancel = (Button) findViewById(R.id.textinputdialog_cancel);
		editText = (EditText) findViewById(R.id.textinputdialog_input);
		title = (TextView) findViewById(R.id.tv_textinputdialog_title);

		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
						| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

		cancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dismiss();
			}
		});
		comfir.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!editText.getText().toString().equals("")) {
					dialogcallback.dialogdo(editText.getText().toString());
				} else {
					Toast.makeText(context, "请输入内容", Toast.LENGTH_SHORT).show();
				}
				dismiss();
			}
		});

	}

	public void setTitle(String string) {
		title.setText(string);
	}

	public void setHint(String str) {
		editText.setHint(str);
	}

	public void setNumInputStyle() {
		editText.setInputType(InputType.TYPE_CLASS_NUMBER);
	}

	public interface Callback {
		public void dialogdo(String string);
	}

	public void setDialogCallback(Callback dialogcallback) {
		this.dialogcallback = dialogcallback;
	}
}